<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('方案列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <input type="hidden"  id="showId" th:value="${showId}">
                            <label>方案分类：</label>
                            <select name="categoryId" id="categoryId" th:with="type=${@dwl.getType('biz_goods_category')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>设备号：</label>
                            <input type="text" id="deviceSn" name="deviceSn" th:value="${deviceSn}"/>
                        </li>
                        <li>
                            <label>方案名称：</label>
                            <input type="text" name="name"/>
                        </li>

                        <li>
                            <label>启用状态：</label>
                            <select name="status" th:with="type=${@dict.getType('enableStatus')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a id="initFeeBtn" style="display: none;" class="btn btn-primary" onclick="initFee()" shiro:hasPermission="biz:fee:init">
                <i class="fa fa-gear"></i> 初始化收费方案
            </a>
            <a id="sendFeeBtn" style="display: none;" class="btn btn-success " onclick="sendFee()" shiro:hasPermission="biz:cargo:sendFee">
                <i class="fa fa-arrow-circle-down"></i> 下发收费方案
            </a>
            <a id="addBtn" style="display: none;" class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="biz:goods:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="biz:goods:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="biz:goods:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="biz:goods:export">
                <i class="fa fa-download"></i> 导出
            </a>
            <a id="closeId" style="display: none;" class="btn btn-warning" onclick="closeItem()">
                <i class="fa fa-reply-all"></i> 返回
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: bootstrap-table-fixed-columns-js" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('biz:goods:edit')}]];
    var removeFlag = [[${@permission.hasPermi('biz:goods:remove')}]];
    var categoryIdDatas = [[${@dwl.getType('biz_goods_category')}]];
    var statusDatas = [[${@dict.getType('enableStatus')}]];
    var prefix = ctx + "biz/goods";

    $(function() {

        var showId = $("#showId").val();
        var deviceSn = $("#deviceSn").val();
        console.log("showId:",showId)
        console.log("deviceSn:",deviceSn)
        if(showId != '' || deviceSn != ''){
            $("#closeId").show();
            $("#sendFeeBtn").show();
            $("#initFeeBtn").show();
            $("#addBtn").show();
        }
        $("#categoryId").val(showId);
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add?categoryId="+showId,
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            fixedColumns: true,
            fixedRightNumber: 1,
            sortName: "sort",
            sortOrder: "asc",
            modalName: "收费方案",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: 'ID',
                    visible: false
                },
                {
                    field: 'deviceSn',
                    title: '设备号',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 20, 'open');
                    }
                },
                {
                    field: 'barCode',
                    title: '功率代码',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 10, 'open');
                    }
                },
                {
                    field: 'name',
                    title: '方案名称',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 10, 'open');
                    }
                },
                {
                    field: 'price',
                    title: '方案价格(KWH/元)',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 10, 'open');
                    }
                },
                {
                    field: 'costPrice',
                    title: '方案进价(KWH/元)',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 10, 'open');
                    }
                },
                {
                    field: 'categoryId',
                    title: '方案分类',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(categoryIdDatas, value);
                    }
                },
                {
                    field: 'sort',
                    title: '排序',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 10, 'open');
                    }
                },
                // {
                //     field: 'diagram',
                //     title: '方案图片',
                //     formatter: function (value, row, index) {
                //         return $.table.imageView(value, 500, 900);
                //     }
                // },
                // {
                //     field: 'descr',
                //     title: '方案详情',
                //     visible: false,
                //     formatter: function (value, row, index) {
                //         return $.table.tooltip(value, 10, 'open');
                //     }
                // },
                // {
                //     field: 'descrDiagram',
                //     title: '详情图',
                //     visible: false,
                //     formatter: function (value, row, index) {
                //         return $.table.tooltip(value, 10, 'open');
                //     }
                // },
                {
                    field: 'status',
                    title: '启用状态',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 10, 'open');
                    }
                },
                {
                    field: 'updateTime',
                    title: '更新时间',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 10, 'open');
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a style="margin-top: 3px;" class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i> 编辑</a> ');
                        actions.push('<a style="margin-top: 3px;" class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i> 删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    /**
     * 初始化收费方案
     */
    function initFee(){
        var deviceSn = $("#deviceSn").val();
        $.modal.confirm("确定初始化收费方案吗？", function() {
            $.operate.get(prefix + "/initFee?deviceSn="+deviceSn,function (result){
                console.log(result);
            })
        })
    }
    /**
     * 下发收费方案
     */
    function sendFee(){
        var deviceSn = $("#deviceSn").val();
        $.modal.confirm("确定下发收费方案吗？", function() {
            $.operate.get(ctx + "biz/cargo/sendFeeBySn?deviceSn="+deviceSn,function (result){
                console.log(result);
            })
        })
    }

</script>
</body>
</html>